<?php


namespace App\Service;


class Lock
{
    private static $prefix = 'lock_';

    public static function lock($key = '', $expire = 1)
    {
        $key = self::$prefix . $key;
        if (!redis()->setnx($key, 1)) {
            return false;
        }
        redis()->expire($key, $expire);
        return true;
    }


    /**
     * 解锁
     * @param $key
     */
    public static function unlock($key)
    {
        $key = self::$prefix . $key;

        return redis()->del($key);
    }

}